package com.df.springmvc.system.role.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.bean.DhtmlGridBean;
import com.df.springmvc.common.bean.MsgBean;
import com.df.springmvc.common.util.WebUtil;
import com.df.springmvc.supper.SupperController;
import com.df.springmvc.system.role.services.RoleServices;

@Controller
@RequestMapping("/system/role/Role")
/**
 * 本类仅做一些简单数据处理如:
 *格式验证
 *数据封装
 * @author David
 *
 */
public class RoleController extends SupperController{
	String page_staff="system/role/" + this.getClass().getSimpleName().replace("Controller","") + "_";
	@Autowired
	RoleServices services;
	@Autowired
	MessageSource messageSource;
	
	public RoleController(){
		// TODO Auto-generated constructor stub
		//
	}
	@RequestMapping(value={"/"})
	public String excute(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		org.apache.log4j.Logger.getLogger(getClass()).info("22333322");
		return page_staff;
	}
	@RequestMapping(value={"/query"})
	public void query(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			DhtmlGridBean gridBean=services.query(getParam_PagingBean(request),getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(gridBean));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping(value={"/" + toView})
	public String toView(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_staff + View;
	}
	@RequestMapping(value={"/toAddGroup"})
	public String toAddGroup(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			addRequestAttribute("groupList",services.queryUserGroup(getParamMap(request,"map").get("roleCode")));
			addRequestAttribute("groupTeamList",services.queryUserTeamGroup(getParamMap(request,"map").get("roleCode")));
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String AddGroup = "AddGroup";
		return page_staff + AddGroup;
	}
	@RequestMapping(value={"/" + toAdd})
	public String toAdd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_staff + Add;
	}
	@RequestMapping(value={"/" + toUpd})
	public String toUpd(ModelMap model,HttpServletRequest request,HttpServletResponse response){

		try{
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_staff + Upd;
	}
	@RequestMapping(value={"/" + toDel})
	public String toDel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		org.apache.log4j.Logger.getLogger(getClass()).info("2222");
		return page_staff + Del;
	}
	@RequestMapping(value={"/" + doAdd})
	public void doAdd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		//WebUtil.json(response,new MsgBean("OK"));
		try{
			Object rs = services.add(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping(value={"/doAddGroup"})
	public void doAddGroup(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		//WebUtil.json(response,new MsgBean("OK"));
		try{
			Object rs = services.addGroup(getParamMap(request));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping(value={"/" + doUpd})
	public void doUpd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			 Object rs=services.upd(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//WebUtil.json(response,new MsgBean("OK"));
	}
	@RequestMapping(value={"/" + doDel})
	public void doDel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		//WebUtil.json(response,new MsgBean("OK"));
		try{
			Object rs=services.del(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
}

